<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group" style="display:none">
        <label class="control-label col-xs-12 col-sm-2">{:__('ID')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-id" class="form-control" name="row[id]" type="text" value="{$row.id|htmlentities}">
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-name" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('类目分类')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select name="row[cate_id]" id="c-cate_id" class="selectpicker" onchange="getSelectValue(this.value)">
                {foreach name="cate" item="vo"}
                   {if condition="$vo.id eq $row['cate_pid']"}
                        <option value="{$vo.id}" selected>{$vo.title}</option>
                    {else/}
                        <option value="{$vo.id}">{$vo.title}</option>
                   {/if}
                {/foreach}
            </select>

            <select name="row[cate_ids]" id="cate_ids" style="width: 200px;padding-right: 25px;height:32.56px;z-index: 1;background-color: #f4f4f4;color: #444;border-color: #ddd;">
                {if condition="$cates neq 0"}
                    <option value="{$cates.id}" selected>{$cates.title}</option>
                {else/}
                    <option value="0">暂无子类目</option>
                {/if}
            </select>
        </div>
    </div>


    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-image" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right" for="c-image"></span>
            </div>
            <ul class="row list-inline faupload-preview" id="p-image"></ul>
        </div>
    </div>
<!--    <div class="form-group">-->
<!--        <label class="control-label col-xs-12 col-sm-2">{:__('Num')}:</label>-->
<!--        <div class="col-xs-12 col-sm-8">-->
<!--            <input id="c-num" class="form-control" name="row[num]" type="number" value="{$row.num|htmlentities}">-->
<!--        </div>-->
<!--    </div>-->

<!--    <div class="form-group">-->
<!--        <label class="control-label col-xs-12 col-sm-2">{:__('Pool')}:</label>-->
<!--        <div class="col-xs-12 col-sm-8">-->
<!--            <input id="c-pool" class="form-control" name="row[pool]" type="number" value="{$row.pool|htmlentities}">-->
<!--        </div>-->
<!--    </div>-->

<!--    <div class="form-group">-->
<!--        <label class="control-label col-xs-12 col-sm-2">{:__('Integer')}:</label>-->
<!--        <div class="col-xs-12 col-sm-8">-->
<!--            <input id="c-integer" class="form-control" name="row[integer]" type="number" value="{$row.integer|htmlentities}">-->
<!--        </div>-->
<!--    </div>-->

<!--    <div class="form-group">-->
<!--        <label class="control-label col-xs-12 col-sm-2">{:__('Money')}:</label>-->
<!--        <div class="col-xs-12 col-sm-8">-->
<!--            <input id="c-money" class="form-control" name="row[money]" type="number" value="{$row.money|htmlentities}">-->
<!--        </div>-->
<!--    </div>-->

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('State')}:</label>
        <div class="col-xs-12 col-sm-8">
            {:build_radios('row[state]', ['1'=>__('No'), '2'=>__('Yes')],$row['state'])}
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Desc')}:</label>
        <div class="col-xs-12 col-sm-8">
            <textarea id="c-desc" class="editor" rows="5" name="row[desc]" cols="50">{$row.desc|htmlentities}</textarea>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <div class="box box-info">
                <div class="panel-body">
                    <div class="form-group row">
                        <div class="col-xs-12">
                            <table class="table fieldlist" data-template="basictpl" data-name="row[basic]" id="first-table">
                                <tr>
                                    <td>{:__('Specs')}</td>
                                    <td>{:__('Money')}</td>
                                    <td>{:__('vipMoney')}</td>
                                    <td>{:__('Stock')}</td>
                                    <td>{:__('Integral')}</td>
                                    <td width="100"></td>
                                </tr>
                                <tr>
                                    <td colspan="5"><a href="javascript:;" class="btn btn-sm btn-success btn-append"><i class="fa fa-plus"></i> {:__('Append')}</a></td>
                                </tr>
                            </table>

                            <!--请注意实际开发中textarea应该添加个hidden进行隐藏-->
                            <textarea name="row[basic]" class="form-control" cols="30" rows="5" style="display:none">{$item}</textarea>

                            <script id="basictpl" type="text/html">
                                <tr class="form-inline">
                                    <td><input type="text" name="<%=name%>[<%=index%>][title]" class="form-control" size="5" value="<%=row.title%>" placeholder="例如：葵花籽油3.9L"/></td>
                                    <td><input type="text" name="<%=name%>[<%=index%>][intro]" class="form-control" size="5" value="<%=row.intro%>" placeholder="例如：65"/></td>
                                    <td><input type="text" name="<%=name%>[<%=index%>][vip_money]" class="form-control" size="5" value="<%=row.vip_money%>" placeholder="例如：40"/></td>
                                    <td><input type="text" name="<%=name%>[<%=index%>][stock]" class="form-control" size="5" value="<%=row.stock%>" placeholder="库存：1"/></td>
                                    <td><input type="text" name="<%=name%>[<%=index%>][integral]" class="form-control" size="5" value="<%=row.integral%>" placeholder="积分：1"/></td>
                                    <td>
                                        <!--下面的两个按钮务必保留-->
                                        <span class="btn btn-sm btn-danger btn-remove"><i class="fa fa-times"></i></span>
                                        <span class="btn btn-sm btn-primary btn-dragsort"><i class="fa fa-arrows"></i></span>
                                    </td>
                                </tr>
                            </script>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>

<script>

    // 获取低
    function getSelectValue(id){
        //发送一个post请求
        $.ajax({
            type:'post',
            url:'goods/goods/cates',
            data:{cate_id:id},
            dataType:'json',
            success:function(data){ //请求成功回调函数
                var status = data.status; //获取返回值
                var address = data.data;
                if(status == 200){ //判断状态码，200为成功
                    var option = '';
                    var option = '<option value="0">暂无子类目</option>'; //默认值
                    for(var i=0;i<address.length;i++){ //循环获取返回值，并组装成html代码
                        option +='<option value="'+address[i]['id']+'">'+ address[i]['title'] +'</option>';
                    }
                }
                $("#cate_ids").html(option); //js刷新第二个下拉框的值
            },
        });
    }

</script>

